package com.region.integral.util;

import java.io.InputStream;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;

import com.region.integral.common_user.obtain.limit.LimitRegulation;


public class XMLIntegralLimitUtil {
	static JAXBContext context = null;
	static {
		try {
			context = JAXBContext.newInstance(LimitRegulation.class);
		} catch (JAXBException e) {
			e.printStackTrace();
		}
	}

	private static void init() {
		if (context == null) {
			try {
				context = JAXBContext.newInstance(LimitRegulation.class);
			} catch (JAXBException e) {
				e.printStackTrace();
			}
		}
	}

	private static InputStream getResource(String resource) {
		InputStream is = XMLIntegralLimitUtil.class.getResourceAsStream("/"+LoadResourcesUtil.getResource(resource));
		return is;
	}

	public static LimitRegulation unmarshaller() {
		LimitRegulation limitRegulation = null;
		init();
		try {
			Unmarshaller unmarshaller = context.createUnmarshaller();
			limitRegulation = (LimitRegulation)unmarshaller.unmarshal(getResource(IntegralConstants.COMMON_USER_INTEGRAL_LIMIT));
		} catch (JAXBException e) {
			e.printStackTrace();
		}
		return limitRegulation;
	}
}
